/*
============================================================================
 Name        : $(Basename)View.cpp
 Author      : $(Author)
 Version     :
 Copyright   : $(Copyright)
 Description : Application view
============================================================================
*/

// INCLUDE FILES
#include <coemain.h>
#include <eikenv.h>
#include "$(Basename)AppView.h"

// ============================ MEMBER FUNCTIONS ===============================

// -----------------------------------------------------------------------------
// C$(Basename)AppView::NewL()
// Two-phased constructor.
// -----------------------------------------------------------------------------
//
C$(Basename)AppView* C$(Basename)AppView::NewL( const TRect& aRect )
	{
	C$(Basename)AppView* self = C$(Basename)AppView::NewLC( aRect );
	CleanupStack::Pop( self );
	return self;
	}

// -----------------------------------------------------------------------------
// C$(Basename)AppView::NewLC()
// Two-phased constructor.
// -----------------------------------------------------------------------------
//
C$(Basename)AppView* C$(Basename)AppView::NewLC( const TRect& aRect )
	{
	C$(Basename)AppView* self = new ( ELeave ) C$(Basename)AppView;
	CleanupStack::PushL( self );
	self->ConstructL( aRect );
	return self;
	}

// -----------------------------------------------------------------------------
// C$(Basename)AppView::ConstructL()
// Symbian 2nd phase constructor can leave.
// -----------------------------------------------------------------------------
//
void C$(Basename)AppView::ConstructL( const TRect& aRect )
	{
	// Create a window for this application view
	CreateWindowL();

	
	TRect sTempRect(aRect);
	sTempRect.iTl.iY = 0;
	SetRect( sTempRect );
	// Set the windows size
	//SetRect( aRect );
	//SetExtentToWholeScreen();
	
	iBitmap = new (ELeave) CWsBitmap(CEikonEnv::Static()->WsSession());

	iBitmap->Create (Rect().Size(),EColor16MU);
	iDevice = CFbsBitmapDevice::NewL (iBitmap );
	iDevice->CreateContext(iGc);
	
	iPeriodic = CPeriodic::NewL(CActive::EPriorityLow);

	// Activate the window, which makes it ready to be drawn
	ActivateL();
	
	if(iPeriodic)iPeriodic->Start(1000000/30, 1000000/30, TCallBack(C$(Basename)AppView::PeriodicCall,this));
	}

// -----------------------------------------------------------------------------
// C$(Basename)AppView::C$(Basename)AppView()
// C++ default constructor can NOT contain any code, that might leave.
// -----------------------------------------------------------------------------
//
C$(Basename)AppView::C$(Basename)AppView()
	{
	// No implementation required
	}


// -----------------------------------------------------------------------------
// C$(Basename)AppView::~C$(Basename)AppView()
// Destructor.
// -----------------------------------------------------------------------------
//
C$(Basename)AppView::~C$(Basename)AppView()
	{
		delete iPeriodic;
		delete iBitmap;
		delete iDevice;
		delete iGc;
	}


// -----------------------------------------------------------------------------
// C$(Basename)AppView::Draw()
// Draws the display.
// -----------------------------------------------------------------------------
//
void C$(Basename)AppView::Draw( const TRect& /*aRect*/ ) const
	{
	// Get the standard graphics context
	CWindowGc& gc = SystemGc();

	// Gets the control's extent
	//TRect drawRect( Rect());

	// Clears the screen
	//gc.Clear( drawRect );
	
	gc.BitBlt(TPoint(),iBitmap);
	
	}

// -----------------------------------------------------------------------------
// C$(Basename)AppView::SizeChanged()
// Called by framework when the view size is changed.
// -----------------------------------------------------------------------------
//
void C$(Basename)AppView::SizeChanged()
	{  
	//DrawNow();
	}
	
	
void C$(Basename)AppView::OnPeriodic()
{
	if (iIsStoped)
	{
		DrawNow();
		return;
	}


	DrawNow();
}

TInt C$(Basename)AppView::PeriodicCall(TAny* aObj)
{
	static_cast<C$(Basename)AppView*> (aObj)->OnPeriodic();
	return 1;
}

TKeyResponse C$(Basename)AppView::OfferKeyEventL( const TKeyEvent& aKeyEvent,TEventCode aType )
{
	if (aType == EEventKey)
	{
		switch (aKeyEvent.iScanCode)
		{
		case EStdKeyDevice3://center key
		case EStdKeySpace:
			iIsStoped = !iIsStoped;
			break;
		}
	}

	return EKeyWasNotConsumed;
}
// End of File